'use strict';
app.controller('merchantsGoodsCtrl',['$scope','utilService','$modal','$stateParams',
    function($scope,utilService,$modal,$stateParams) {
    $scope.goods = {
        shopId :$stateParams.shopId
    };
    $scope.queryShopGoods = function () {
        utilService.queryForPagingList($scope, {
            url: $scope.app.domain + 'goods/shop/list',
            params:$scope.goods
        }).then(function (result) {
        });
    }
    $scope.queryShopGoods();

    //打开查看服务框
    $scope.checkReserve = function (id) {
        var modalInstance = $modal.open({
            templateUrl: 'tpl/goods/reserve_info.html',
            controller: 'reserveInfoCtrl',
            size: 'md',
            scope:$scope,
            resolve: {
                data: function () {
                    return id;
                }
            }
        });

        modalInstance.result.then(function (selectedItem) {
            $scope.selected = selectedItem;
        }, function () {
            console.info('Modal dismissed at: ' + new Date());
        });
    };
}]);

app.controller('reserveInfoCtrl',['$scope','toaster','data','$modalInstance','merchantsGoodsService',
    function($scope,toaster,data,$modalInstance,merchantsGoodsService){
        $scope.id=data;
        $scope.goodsInfo={};

        $scope.checkReserve=function(){
            merchantsGoodsService.checkReserve($scope).then(function (result) {
                switch (result.status) {
                    case 200:
                        $scope.goodsInfo=result.data;
                        break;
                    default :
                        toaster.pop('error', "操作失败", "发生未知错误！请联系管理员");
                        break;
                }
            })
        };

        $scope.checkReserve();

        $scope.ok = function(){
            $modalInstance.dismiss('cancel');
        };

    }]);

//强制下架
app.controller('goodsSoldOutCtrl',['$scope','$stateParams','merchantsGoodsService','toaster','$state',
    function($scope,$stateParams,merchantsGoodsService,toaster,$state) {
    $scope.merchants={
        id:$stateParams.id,
        shopId:$stateParams.shopId
    }
    $scope.changeStatus=function(){
        merchantsGoodsService.changeStatus($scope).then(function(result){
            switch (result.status){
                case 200:
                    toaster.pop('success', "提示", "操作成功");
                    history.back();
                    break;
                case 673:
                    toaster.pop('error', "提示", "提示：该商品并未上架！");
                    break;
                default :
                    toaster.pop('error', "操作失败", "发生未知错误！请联系管理员");
                    break;
            }
        });
    }

}]);